/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once
#include <baja/common.hpp>
#include <baja/assert.hpp>
#include <journal/common/settings_service.hpp>

#define TRACE_TAG_INPUT 0x1
#define TRACE_TAG_INK 0x2
#define TRACE_TAG_MODEL 0x4
#define TRACE_TAG_MODEL_CACHE_MGR 0x8
#define TRACE_TAG_PAGE_VIEW 0x10
#define TRACE_TAG_KEYS 0x20
#define TRACE_TAG_INK_RENDERER 0x40
#define TRACE_TAG_INK_RENDERER_PERF 0x80
#define TRACE_TAG_INK_DELETE 0x100
#define TRACE_TAG_THUMBNAILS 0x200
#define TRACE_TAG_UNDO_REDO 0x400
#define TRACE_TAG_GENERIC_MODEL 0x800
#define TRACE_TAG_RECORDED 0x1000
#define TRACE_TAG_SLOTS 0x2000
#define TRACE_TAG_OTHER 0xf0000000
// special tag to always show these traces no matter what
#define TRACE_TAG_ALWAYS 0x1000000

namespace journal { namespace app {

namespace b = baja;

struct trace_tag_registry : public std::enable_shared_from_this<trace_tag_registry>, public isettings_service_observer
{
    trace_tag_registry() : _settingsObserverCookie(-1) {}
    static void initialize();
    static void initialLoad();

    // isettings_service_observer
    void onBeforeSettingChange(const b::wchar* fullName);
    void onAfterSettingChange(const b::wchar* fullName);

private:
    struct trace_tag_data
    {
        std::wstring path;
        b::uint64 tag;
        bool b;
    };

    void initializeInternal();
    void registerTag(const b::uint64 tag, const b::wchar* path, const bool defaultValue);

    static std::shared_ptr<trace_tag_registry> _singleton;
    b::int32 _settingsObserverCookie;
    std::map<std::wstring, trace_tag_data> _map;
};

}} // namespace journal::app